package org.jeecg.modules.xl.order.mapper;

import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.*;
import org.jboss.marshalling.ObjectTable;
import org.jeecg.modules.xl.h5api.vo.MyStoreDataVO;
import org.jeecg.modules.xl.h5api.vo.MyStoreVO;
import org.jeecg.modules.xl.order.entity.XlCustomerOrde;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.jeecg.modules.xl.order.vo.OrderExport;
import org.jeecg.modules.xl.order.vo.XlCustomerOrdeCityVO;
import org.jeecg.modules.xl.order.vo.XlCustomerOrdeVO;

/**
 * @Description: xl_customer_order
 * @Author: jeecg-boot
 * @Date:   2024-10-20
 * @Version: V1.0
 */
public interface XlCustomerOrdeMapper extends BaseMapper<XlCustomerOrde> {

    @Select("" +
            "SELECT  " +
            "    MAX(SUBSTRING(SUBSTRING_INDEX(order_code, #{pre}, -1), 1)) AS maxNumber " +
            "FROM  " +
            "    xl_customer_orde " +
            "WHERE  " +
            "    order_code LIKE concat('%',#{pre},'%') " +
            "")
    String queryMaxCodeNumber(String pre);


    @Select("select t3.order_code as orderCode,t3.create_time as createTime,'SO' as orderType, t3.store_name as storeName,t3.store_code as storeCode,\n" +
            "t2.product_name as productName,t2.upc_code as upcCode,t2.product_spec as productSpec ,t2.carton_spec as cartonSpec,\n" +
            "t1.order_quantity as orderQuantity,t1.product_price as productPrice,t1.order_amount as orderAmount,'748387'as wareHouseId\n" +
            " from xl_customer_order_detail t1 \n" +
            "left join xl_product_info t2 on t1.upc_code = t2.upc_code\n" +
            "left join xl_customer_orde t3 on t1.order_code = t3.order_code\n" +
            "where t2.brand=#{brand} and DATE_FORMAT(t3.create_time, '%Y%m') =  #{month} and t3.order_status='已收货' ORDER BY t3.order_code")
    List<Map> queryBrandOfOrderDetail(@Param("brand") String brand,@Param("month") int month);
    /**
     * 自定义查询订单
     * @param wrapper
     * @return
     */
    Page<XlCustomerOrdeVO> queryList(@Param("page") Page<XlCustomerOrde> page,@Param(Constants.WRAPPER) Wrapper<XlCustomerOrde> wrapper);

    /**
     * 修改订单的 发货单号
     * @param orderCode
     * @return
     */
    @Update("" +
            " UPDATE xl_customer_orde t2 " +
            " SET delivery_codes = ( " +
            "    SELECT GROUP_CONCAT(delivery_code SEPARATOR ', ') " +
            "    FROM xl_customer_shipment t1 " +
            "    WHERE t1.order_code = t2.order_code " +
            " ) where order_code = #{orderCode} " +
            "")
    int upDeliveryCodes(String orderCode);



    /**
     * 城配订单
     * @param city
     * @return
     */
    List<XlCustomerOrdeCityVO> queryCityList(@Param("city") String city,@Param("orderCode") String orderCode);

    // List<OrderExport> getOrderExport( @Param("orderCode") String orderCode,  @Param("startTime") Date startTime,  @Param("endTime")  Date endTime);


    List<OrderExport> exportOrderDetailS( @Param(Constants.WRAPPER) Wrapper<OrderExport> wrapper);

    List<XlCustomerOrde> exportOnlyOrder( @Param(Constants.WRAPPER) Wrapper<OrderExport> wrapper);

    @MapKey("order_code")
    Map<String,Map<String, Object>> selectOrdersAfterAmount(@Param("orders") String orders);

    List<MyStoreDataVO> getMyStoreData(@Param("stores")  String  stores);

    List<MyStoreVO> getStoreUnpayAmount(@Param("storeCode") String storeCode);

    /**
     *
     * @param storeCode
     * @return
     */
    List<Map> getCornerNum(@Param("storeCode") String storeCode);

    /**
     * 新-订单查询
     * @param page
     * @param wrapper
     * @return
     */
    Page<XlCustomerOrde> orderQueryPageNew(@Param("page") Page<XlCustomerOrde> page,@Param(Constants.WRAPPER) Wrapper<XlCustomerOrde> wrapper);


}
